package com.econ.powercloud.ems.domain;

import com.econ.powercloud.common.base.facade.util.JacksonUtil;
import com.econ.powercloud.ems.constant.SysConstant;
import com.econ.powercloud.ems.dal.entity.EmsColumnConfigDevice;
import com.econ.powercloud.ems.pojo.EmsColumnConfigDeviceVO;

import java.util.List;

/**
 * @Author : zjf
 * @Description :
 * @Date : 2021/10/21 14:32
 * @Modified by : zjf
 */
public class EmsColumnConfigDeviceDO {

    /**
     * 集合 实体类->VO类
     */
    public static List<EmsColumnConfigDeviceVO> entityListToVOList(List<EmsColumnConfigDevice> configDevices){
        List<EmsColumnConfigDeviceVO> configDeviceVOS = JacksonUtil.convertToList(configDevices, EmsColumnConfigDeviceVO.class);
        configDeviceVOS.stream().forEach(d->{
            if(d.getSorting() != null){
                String[] locations = d.getSorting().split(SysConstant.CABLE);
                //赋值坐标位置,如果不是二维坐标,则横坐标不需要赋值
                d.setGroup(locations.length >1?Integer.parseInt(locations[1]): SysConstant.ONE_INTEGER);
                d.setCross(Integer.parseInt(locations[0]));
            }
        });
        return configDeviceVOS;
    }
}
